<h2>
  <%= (@status || 'all').humanize %>&nbsp;&nbsp;
  <% if current_admin.can? :create_mail %>
  <%= link_to new_promotion_mail_path do %>
    <i class="fa fa-plus-circle fa-lg"></i>
  <% end %>
  <% end %>
</h2>
<ul class="list-group container">
  <% @promotion_mails.each do |mail| %>
  <li class="list-group-item row dropdown">
    <div class="col-lg-1">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-chevron-down"></i></a>
      <ul class="dropdown-menu container well well-sm">
        <% mail.deliveries.each do |delivery| %>
        <li class="row">
          <div class="col-lg-2"><%= delivery.domain_name %></div>
          <div class="col-lg-2"><%= delivery.status.to_s.humanize %></div>
          <div class="col-lg-2">
            <% if pause_available?(delivery) %>
            <a class="pause_delivery" href="#" delivery_id="<%= delivery.id %>">
              <i class="fa fa-pause fa-lg"></i>
            </a>
            <% end %>

            <% if resume_available?(delivery) %>
            <a class="resume_delivery" href="#" delivery_id="<%= delivery.id %>">
              <i class="fa fa-play fa-lg"></i>
            </a>
            <% end %>

            <% if stop_available?(delivery) %>
            <a id="stop_delivery" href="#" delivery_id="<%= delivery.id %>">
              <i class="fa fa-stop fa-lg"></i>
            </a>
            <% end %>
          </div>
          <div class="col-lg-2">
            <span class="badge"><%= delivery.sent %></span>
          </div>
        </li>
        <% end %>
      </ul>
    </div>
    <div class="col-lg-1">#<%= mail.id %></div>
    <div class="col-lg-4">
      <%= link_to mail.subject, mail %>
      <%= span_if mail.draft?, class: 'text-primary' do %>
        <i class="fa fa-asterisk"></i>
      <% end %>
    </div>
    <div class="col-lg-2"><%= mail.status.humanize %></div>
    <div class="col-lg-2">
      <% if deliver_available?(mail) %>
      <%= link_to [:deliver, mail] do %>
        <i class="fa fa-play-circle fa-lg"></i>
      <% end %>
      <% end %>

      <% if pause_available?(mail) %>
      <a class="pause_mail" href="#" mail_id="<%= mail.id %>">
        <i class="fa fa-pause fa-lg"></i>
      </a>
      <% end %>

      <% if resume_available?(mail) %>
      <a class="resume_mail" href="#" mail_id="<%= mail.id %>">
        <i class="fa fa-play fa-lg"></i>
      </a>
      <% end %>

      <% if stop_available?(mail) %>
      <a class="stop_mail" href="#" mail_id="<%= mail.id %>">
        <i class="fa fa-stop fa-lg"></i>
      </a>
      <% end %>

      <% if current_admin.can? :create_mail %>
      <%= link_to mail, method: :delete do %>
        <i class="fa fa-trash-o fa-lg"></i>
      <% end %>
      <% end %>
    </div>
    <div class="col-lg-2">
      <span class="badge"><%= mail.deliveries.reduce(0){|sum, d| sum + d.sent} %></span>
    </div>
  </li>
  <% end %>
</ul>
